﻿@model PhoneBilling.Models.GradesMgtModel
@{
    ViewBag.Title = "收费等级表管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
    function del(id, name) {
        var r = confirm("确认删除收费等级：" + name + "吗？");
        if (r == true) {
            window.location.href = "/Manage/GradeDelete?id=" + id;
        }
        return false;
    }
</script>
@if (Model.Message != null){<h2>@Model.Message</h2>}
<div class="system_toolbar">
    <input type="button" id="btnNew" value="新增" />
    <input type="button" id="btnModify" value="修改" />
    <input type="button" id="btnDelete" value="删除" />
</div>    
@*@{
    var grid = new WebGrid(source: Model.GradeList, rowsPerPage: 30);
}*@
@{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.AppendLine(string.Format("var data={{Total:{0},", Model.GradeList.Count));
    sb.AppendLine("Rows:[");
    for (int i = 0; i < Model.GradeList.Count; i++)
    {
        var item = Model.GradeList[i];
        if(i == 0)
        {
            sb.Append("{");
        }
        else
        {
            sb.Append(",{");
        }
        sb.Append(string.Format("ID:'{0}',", item.ID));
        sb.Append(string.Format("Name:'{0}',",item.Name));
        sb.Append(string.Format("Remark:'{0}'", item.Remark));
        sb.Append("}");
    }
    sb.AppendLine("]};");
    string data = sb.ToString();
}
<script type="text/javascript">
    @Html.Raw(data)
    
    var menu = $.ligerMenu({ top: 100, left: 100, width: 120, items:
            [
            { text: '新增', click: newclick },
            { line: true },
            { text: '修改', click: modifyclick },
            { line: true },
            { text: '删除', click: deleteclick }
            ]
        });
    var grid;
    $(function () {

        grid = $("#maingrid").ligerGrid({
            columns: [
                { display: '用户名', name: 'Name',width:160},
                { display: '备注', name: 'Remark',width:400 }],
                isScroll: false, data: data,pageSize:30,alternatingRow:true,  
                onContextmenu: function (node, e) {
            actionNodeID = node;
            menu.show({ top: e.pageY, left: e.pageX });
            return false;
        }
        }
        );resetGridHeight(grid);
        $(window).resize(function () {
                resetGridHeight(grid);
            });
    });    function newclick(item, i) {
        var path = "/Manage/GradeEdit";
        window.location.href=path;
    }
    function modifyclick(item, i) {
        var path = "/Manage/GradeEdit?id="+actionNodeID.data.ID;
        window.location.href=path;
    }    function deleteclick(item, i) {
        del(actionNodeID.data.ID,actionNodeID.data.Name);
    }
    $(document).ready(function () {
        $("#btnNew").ligerButton(
        {
            click: function () {
                window.location.href = "/Manage/GradeEdit";
            }
        });
        $("#btnModify").ligerButton(
        {
            click: function () {
                var row = grid.getSelectedRow();
                if(row != null)
                {
                    var path = "/Manage/GradeEdit?id="+row.ID;
                    window.location.href=path;
                }
            }
        });

        $("#btnDelete").ligerButton(
        {
            click: function () {
                var row = grid.getSelectedRow();
                if(row != null)
                {
                    del(row.ID,row.Name);
                }
            }
        });
    });
</script>
<div id="maingrid"></div>
@*@{
    var grid = new WebGrid(source: Model.GradeList, rowsPerPage: 30);
}
@grid.GetHtml(
    alternatingRowStyle: "bg",
    columns:grid.Columns
    (
        grid.Column("Name","收费等级表"),
        grid.Column("Remark", "备注"),
        grid.Column(format:(item)=> Html.ActionLink("修改","GradeEdit",new {id=item.ID})),
        grid.Column(format: (item) => Html.Raw(string.Format("<a href='javascript:' onclick=\"del('{0}','{1}')\">删除</a>", item.ID, item.Name)))
    )
)*@



